/*
*	冰火家族萬能NPC
*
*
*
*
*
*/
var x = "#fEffect/CharacterEff/1112949/0/0#";//高音譜記號
var kk = "#fEffect/BasicEff/MainNotice/Boss/Default/0#";//BOSS
var c = "#fEffect/CharacterEff/1032063/0/0#";//"#fUI/UIMiniGame/starPlanetRPS/heart#";//愛心
var cmark = "#fUI/UIPVP/ChampionMark/1#";//愛心
var lb = "#fEffect/ItemEff/1112811/0/0#";//藍色小光
var b = "#fEffect/CharacterEff/Shaman/1#";//超萌熊熊
var cat = "#fEffect/CharacterEff/Shaman/4#";//超萌喵咪
var leaf = "#fUI/Basic.img/Cursor/18/0#";
var status;
var sele1;
var scrollsrc;
var scrolls;

var menuList = Array(
        Array(lb, "裝備痕跡", 0, true),
		Array(lb, "星力強化", 1, true)
		);
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {

    if (mode == 0) {
	cm.dispose();
	return;
    } else if (mode == 1){
	status++;
    } else {
	status--;
    }

    switch (status) {
        case 0: 
			text = "\t  "+c+"#fn华文行楷##fs30##e#k #b星力強化 " +c+ "\r\n#fs12##fn宋体#";
			
			var ccc = 0;
			for (var i = 0; i < menuList.length; i++) {
				if(ccc%3 == 0)
					text +="\r\n   ";
				if (menuList[i][3]) { // 如果允许显示
					text += "#d#L" + menuList[i][2] + "#" + menuList[i][0] + menuList[i][1] + "#l";
					ccc++;
				}
			}
			text += "\r\n\r\n\t\t   #L999#" + leaf +"#fn华文行楷##fs22##e#r回上一頁#l"
			text += "\r\n\r\n  " +c+c+c+c+c+c;
			cm.sendSimple(text);
            break;
        case 1: //
			sele1 = selection;
			switch (selection){
				case 0://裝備痕跡
					var inventoryType = 1;
					text = "#e經過篩選，以下為所有裝備痕跡#n\r\n#r您可以在此使用抵用券轉換痕跡道具，也可以使用相同道具在裝備強化介面轉換。\r\n#e***注意:轉換後將從 0 星開始***#n\r\n\r\n#b";
					var list = cm.getInventory(inventoryType).list();
					var itemList = list.iterator();
					newItemList = new Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						if(cm.isTrace(item.getPosition()))
							newItemList[item.getPosition()] = item.getItemId();
						else
							continue;
					}
					var xx = 0;
                    for (var key in newItemList) {
                        xx++;
						var eqp = cm.getInvEquip(key);
						var eqp_star = eqp.getEnhance();
						var cost = eqp_star * eqp_star * 99786;
                        text += "#L" + key + "##v" + newItemList[key] + "# - "+cost+ " 抵用券 #l\r\n";
                    }
					if (xx <= 0) {
						text = "您沒有痕跡裝備"
						cm.sendOk(text);
						cm.dispose();
                    }else{
						cm.sendSimple(text);
					}
					break;
				case 1://星力強化
					var inventoryType = 1;
					text = "#e經過篩選，以下為所有可進行星力強化裝備#n\r\n#r詳細機率請見教學。\r\n\r\n#b";
					var list = cm.getInventory(inventoryType).list();
					var itemList = list.iterator();
					newItemList = new Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						var eqp = cm.getInvEquip(item.getPosition());
						if(eqp.getUpgradeSlots() == 0 && cm.getMaxEnhance(eqp) > 0 && !cm.isTrace(item.getPosition()))
							newItemList[item.getPosition()] = item.getItemId();
						else
							continue;
					}
					var xx = 0;
                    for (var key in newItemList) {
                        xx++;
						var eqp = cm.getInvEquip(key);
						var eqp_star = eqp.getEnhance();
						var meso_Cost = 0;
						var nx_Cost = 0;
						var ii = cm.getMapleItemInformationProvider();
						if (ii.isSuperiorEquip(eqp.getItemId())) {
							meso_Cost = 11200000;
							nx_Cost = 1050000;
						} else{
							meso_Cost = eqp.getEnhance() * eqp.getEnhance() * 100000;
							nx_Cost = eqp.getEnhance() * eqp.getEnhance() * 10000 * 2;
						}
                        text += "#L" + key + "##v" + newItemList[key] + "# - "+nx_Cost+ " 抵用券 & "+ meso_Cost +" 楓幣#l\r\n";
                    }
					if (xx <= 0) {
						text = "您沒有可進行星力強化的裝備!"
						cm.sendPrev(text);
                    }else{
						cm.sendSimple(text);
					}
					break;
				case 999://回上一頁
					cm.dispose();
					cm.openNpc(1052253, 1);
					break;
				default:
					cm.sendOk(menuList[selection][1] + " 正在籌備中!敬請期待。");
					cm.dispose();
					break;
			}
            break;
		case 2:
			if(sele1 == 0){
				var eqp = cm.getInvEquip(selection);
				var eqp_star = eqp.getEnhance();
				var cost = eqp_star * eqp_star * 99786;
				if(cm.getNX(2) > cost){
					if(cm.getInvEquip(selection)){
						if(cm.doTrace(selection))
							cm.sendOk("成功回復 " + cost);
						else
						cm.sendOk("發生錯誤!");
					}
				}else{
					cm.sendOk("您沒有足夠的抵用券");
				}
				cm.dispose();
			}else{
				scrollsrc = selection;
				var inventoryType = 2;
					text = "#e經過篩選，以下為所有可進使用之裝備強化捲#n\r\n#r詳細機率請見教學。\r\n\r\n#b";
					var list = cm.getInventory(inventoryType).list();
					var itemList = list.iterator();
					newItemList = new Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						var eqp = cm.getInvEquip(item.getPosition());
						if(item.getItemId() == 2049323 || item.getItemId() == 2049301)
							newItemList[item.getPosition()] = item.getItemId();
						else
							continue;
					}
					var xx = 0;
                    for (var key in newItemList) {
                        xx++;
						var eqp = cm.getInvEquip(key);
                        text += "#L" + key + "##v" + newItemList[key] + "# #z"+newItemList[key]+"# #l\r\n";
                    }
					if (xx <= 0) {
						text = "您沒有可進行星力強化的裝備!"
						cm.sendPrev(text);
                    }else{
						cm.sendSimple(text);
					}
					break;
			}
			break;
		case 3:
			scrolls = selection;
			cm.dispose();
			cm.NPCenhance(scrolls,scrollsrc);
			break;
        default:
			cm.sendOk("發生錯誤，請聯繫管理員!");
			cm.dispose();
			break;
    }
}
